package com.itheima.controller;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet("/LoginServlet")
public class LoginServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

       String  username = req.getParameter("username");
        String password = req.getParameter("password");
        String yan2 = req.getParameter("yan");
        HttpSession yan = req.getSession();
        String yan1 = (String) yan.getAttribute("yan");
        HttpSession session = req.getSession();
        session.setAttribute("username",username);
        if("张三".equals(username)&&"123".equals(password)&&yan2.equals(yan1)){
            resp.sendRedirect("/jsp/Manager.jsp");
        }else{
            req.setAttribute("msg","用户名或密码错误或验证码错误");
            req.getRequestDispatcher("/Login.jsp").forward(req,resp);
        }

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req,resp);
    }
}
